using System;
using System.Collections.Generic;
using System.Text;

namespace Dbam.DbFramework.SampleConsole
{
	class Program
	{
		static void Main(string[] args)
		{
			SqlDbFactory dbFactory = new SqlDbFactory(Settings.Default.DbConnectionString);
			ObjectRelationalMapper<Account> ormAccount = new ObjectRelationalMapper<Account>(dbFactory);
			ObjectRelationalMapper<Session> ormSession = new ObjectRelationalMapper<Session>(dbFactory);

			// create entity example
			Account account = new Account();
			account.Name = "My First Account";
			account.OpenDate = DateTime.Parse(@"1/2/2004");
			account.LastLogon = null;
			ormAccount.Insert(account);
			for(int index = 1; index <= 5; index++)
			{
				Session session = new Session();
				session.ParentAccountId = account.Id;
				ormSession.Insert(session);
				account.Sessions.Add(session);
			}

			// update the session entity
			account.Sessions[1].BeginTime = DateTime.Parse("5/5/2005");
			ormSession.Update(account.Sessions[1]);

			// change entity, then undo the change by re-reading the entity from
			// the database.
			account.Sessions[2].EndTime = DateTime.Parse("2/27/2700");
			ormSession.Select(account.Sessions[2]);

			// delete entity
			ormAccount.Delete(account);
			bool stillExists = ormAccount.Exists(account);
		}
	}
}